﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Clothes.BLL;
using Clothes.IBLL;
using Clothes.Model;

namespace YongHu_UI
{
    public partial class contact : System.Web.UI.Page
    {
        public int idd;
        public int wei;
        public string xing;
        public string shou;
        public string tu;
        public string jian;
        public int shu;
        public int? jin;
        public string di;
        CLUserIBLL user = new CLUserBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            var list = Model.IdentityManager.ReadUser();
            if (list==null) {
                Response.Redirect("login.aspx");
            }
            int id =Convert.ToInt32(Request.QueryString["id"]);
            idd = Model.IdentityManager.ReadUser().Id;
            
            shoppingIBLL shop = new shoppingBLL();
            CLUser clu = user.Select(idd);
            shopping ping = shop.SelectId(id);

            xing = "";
            shou = "";
            di = "";

            if (clu != null)
            {
                xing = clu.NickName;
                di = clu.Address;
                shou = clu.MobileNumber;
            }

            
            tu = ping.Avatar;
            jian = ping.Summary;
            shu = ping.Number;
            jin = ping.Money;
            wei =Convert.ToInt32(ping.CLDressId);
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (xing == "" && di == "")
            {
                CLUser user1 = new CLUser()
                {
                    NickName = TextBox1.Text,
                    Avatar=null,
                    CLLoginId=idd,
                    Sex=0,
                    Birthday=null,
                    Address=TextBox3.Text,
                    CreationTime=DateTime.Now,
                    MobileNumber=TextBox2.Text
                };
                user.InsertBLL(user1);
                Response.Redirect("contact.aspx?id="+idd);
            }
            else {
                user.SelectEdit(idd, TextBox1.Text, TextBox3.Text, TextBox2.Text);
                Response.Redirect("contact.aspx?id="+idd);
            }
             
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            CLDressIBLL cLDress = new CLDressBLL();
            cLDress.Edit(wei,shu);
            ClientScript.RegisterStartupScript(GetType(), "loginerror", "alert('购买成功');loction.href='checkout.aspx';", true);
        }
    }
}